home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / KEYLED.ZIP / KEYLED.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-04-23  |  3.4 KB  |  145 lines

  1. program Keyboard_LED_Fun;
  2.  
  3. { 20 October 1992 }
  4.  
  5. {
  6.   By Morbid Man
  7. }
  8.  
  9. uses
  10.   Crt;
  11.  
  12. var
  13.   Count : byte;
  14.  
  15. {
  16.  
  17.   Table for status bytes being changed:
  18.  
  19.   Bit     Key
  20.  
  21.    7      Insert
  22.    6      Caps Lock
  23.    5      Num Lock
  24.    4      Scroll Lock
  25.    3      Alt shift
  26.    2      Ctrl shift
  27.    1      Left shift key
  28.    0      Right shift key
  29.  
  30.   When the changed bit = 1, the keyboard and computer assume that the
  31.   key described has been pressed.  I am illustrating the use of this
  32.   nifty code by messing with the keyboard Light Emitting Diodes (the
  33.   idiot lights that turn on when you hit a Caps Lock, Num Lock, or
  34.   Scroll Lock -- if your keyboard has them).
  35.  
  36.   If you get the byte that holds this information, and you AND
  37.   the bit that you want the keyboard to read as having been pressed,
  38.   it thinks you pressed it and should change the LED accordingly.
  39.  
  40.   If you get the byte and OR the bit ( 0 OR 0 = 0, 1 OR 0 = 1, 1 OR 1 = 1)
  41.   it turns off the "key" that you pressed, via the software!
  42.   (This is called programming to the metal!)  Nifty, huh?
  43.  
  44.   I've played around with this randomizing Count (so it would just blink
  45.   at differing intervals, in no particular order.  I've also had
  46.   it scroll to the left.  Anybody got any other ideas?  If so, send them
  47.   to me!  (Hmmm...how about messing with disk drive lights?...)
  48.  
  49.   Here's an idea -- a mod player, that lets you sync the led's to a
  50.   channel!
  51.  
  52. }
  53.  
  54. procedure NumLockOn; assembler;
  55.  
  56.   asm
  57.     sub ax, ax                        { Set the extra segment to 0 }
  58.     mov es, ax
  59.     mov al, 100000b                   { Turn on bit 5              }
  60.     or es:[417h], al                  { Change the status byte     }
  61.   end;
  62.  
  63. procedure NumLockOff; assembler;
  64.  
  65.   asm
  66.     xor ax, ax                        { Set the extra segment to 0 }
  67.     mov es, ax
  68.     mov al, 11011111b                 { Turn bit 5 off             }
  69.     and es:[417h], al                 { Change the status byte     }
  70.   end;
  71.  
  72. procedure CapsLockOn; assembler;
  73.  
  74.   asm
  75.     xor ax, ax
  76.     mov es, ax
  77.     mov al, 1000000b
  78.     or es:[417h], al
  79.   end;
  80.  
  81. procedure CapsLockOff; assembler;
  82.  
  83.   asm
  84.     xor ax, ax
  85.     mov es, ax
  86.     mov al, 10111111b
  87.     and es:[417h], al
  88.   end;
  89.  
  90. procedure ScrollLockOn; assembler;
  91.  
  92.   asm
  93.     xor ax, ax
  94.     mov es, ax
  95.     mov al, 10000b
  96.     or es:[417h], al
  97.   end;
  98.  
  99. procedure ScrollLockOff; assembler;
  100.  
  101.   asm
  102.     xor ax, ax
  103.     mov es, ax
  104.     mov al, 11101111b
  105.     and es:[417h], al
  106.   end;
  107.  
  108. begin
  109.   Randomize;
  110.   Count := 0;
  111.   NumLockOff;
  112.   CapsLockOff;
  113.   ScrollLockOff;
  114.   ClrScr;
  115.   WriteLn ('Keyboard LED Demo.');
  116.   WriteLn;
  117.   WriteLn ('Press any key to quit...');
  118.   WriteLn ('Look at your keyboard!!!  :)');
  119.   repeat
  120.     inc (Count);
  121.     case Count of
  122.       1 : begin
  123.             CapsLockOff;
  124.             NumLockOn
  125.           end;
  126.       2 : begin
  127.             CapsLockOn;
  128.             NumLockOff
  129.           end;
  130.       3 : begin
  131.             ScrollLockOn;
  132.             CapsLockOff
  133.           end;
  134.       4 : begin
  135.             ScrollLockOff;
  136.             CapsLockOn
  137.           end;
  138.     end;
  139.     if Count = 4 then Count := 0;
  140.     delay (250)                           { If you leave the delay out  }
  141.   until keypressed;                       { it may not let you quit the }
  142.   NumLockOff;                             { loop!  It will go too fast! }
  143.   CapsLockOff;
  144.   ScrollLockOff
  145. end.